-
-
Notifications
You must be signed in to change notification settings - Fork 68
Tracking: Rust Bindings #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've hit compilation issues on M1 iMac. @asg017 Could we get some more precise docs for using the Rust bindings? Maybe you can distill my experience into better/more documentation for compiling Context[dependencies]
rusqlite = { version = "0.29.0", features = ["bundled"] }
sqlite-vss = { version = "0.1.1", features = ["download-libs"] } // build.rs
fn main() {
if cfg!(target_os = "macos") {
println!("cargo:rustc-link-arg=-Wl,-undefined,dynamic_lookup,-lomp");
} else if cfg!(target_os = "linux") {
println!("cargo:rustc-link-arg=-Wl,-undefined,dynamic_lookup,-lstdc++");
}
} // main.rs
use rusqlite::{ffi::sqlite3_auto_extension, Connection, Result};
use sqlite_vss::{sqlite3_vector_init, sqlite3_vss_init};
fn main() -> Result<()> {
unsafe {
sqlite3_auto_extension(Some(sqlite3_vector_init));
sqlite3_auto_extension(Some(sqlite3_vss_init));
}
let db = Connection::open_in_memory()?;
let (version, vector): (String, String) = db.query_row(
"SELECT vss_version(), vector_to_json(?)",
[[0x00, 0x00, 0x28, 0x42]],
|row| Ok((row.get(0)?, row.get(1)?)),
)?;
println!("version={version} vector={vector}");
Ok(())
} What I did$ cargo run
Compiling sqlite-vss-demo v0.1.0
error: linking with `cc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="..."
# ... clipped ...
= note: ld: library not found for -lomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile `sqlite-vss-demo` (bin "sqlite-vss-demo") due to previous error I saw #61, which mentioned an argument for $ brew install libomp
==> Fetching libomp
==> Downloading https://ghcr.io/v2/homebrew/core/libomp/manifests/16.0.6
==> Downloading https://ghcr.io/v2/homebrew/core/libomp/blobs/sha256:3dee22dd4f55d9bb85cc5b89ae5d99e6e2f52b151ca8768c9f71e41cf88f9986
==> Pouring libomp--16.0.6.arm64_monterey.bottle.tar.gz
==> Caveats
libomp is keg-only, which means it was not symlinked into /opt/homebrew,
because it can override GCC headers and result in broken builds.
For compilers to find libomp you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/libomp/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libomp/include" I ran the Rust compiler again, but there was no change. $ cargo run
Compiling sqlite-vss-demo v0.1.0
error: linking with `cc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="..."
# ... clipped ...
= note: ld: library not found for -lomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile `sqlite-vss-demo` (bin "sqlite-vss-demo") due to previous error I noticed the "Caveat " that Homebrew installed ==> Caveats
libomp is keg-only, which means it was not symlinked into /opt/homebrew,
because it can override GCC headers and result in broken builds.
For compilers to find libomp you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/libomp/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libomp/include" So I ran cargo again, with the RUSTFLAGS="-L/opt/homebrew/opt/libomp/lib -L/opt/homebrew/opt/llvm/lib -lblas -llapack" cargo run
Compiling ...
# ... clipped ...
Finished dev [unoptimized + debuginfo] target(s) in 12.46s
Running `target/debug/sqlite-vss-demo`
version=v0.1.1 vector=[42.0] Questions for the Docs:
|
The Rust bindings are no longer compatible with later versions of |
I was able to load sqlite-vss dynamically using sqlx. I personally want to statically compile it and filed a feature request for sqlx since it doesn't support it. launchbadge/sqlx#3147 (comment). They do mention that the current signature for sqlite-vss is not correct. Would be great if it was changed such that it would be compatible with newer version of rusqlite. Then could also add feature in sqlx to support it so the same signature works for both libraries. |
I have managed to load the extension into sqlx by directly calling use sqlite_vss::{sqlite3_vector_init, sqlite3_vss_init};
unsafe {
let vss_vector_init = sqlite3_vector_init as *const ();
let vss_vector_init_correct: extern "C" fn(
db: *mut sqlite3,
pzErrMsg: *mut *const c_char,
pThunk: *const sqlite3_api_routines,
) -> i32 = std::mem::transmute(vss_vector_init);
libsqlite3_sys::sqlite3_auto_extension(Some(vss_vector_init_correct));
let vss_init = sqlite3_vss_init as *const ();
let vss_init_correct: extern "C" fn(
db: *mut sqlite3,
pzErrMsg: *mut *const c_char,
pThunk: *const sqlite3_api_routines,
) -> i32 = std::mem::transmute(vss_init);
libsqlite3_sys::sqlite3_auto_extension(Some(vss_init_correct));
} I also had to add the following to the fn main() {
if cfg!(target_os = "macos") {
println!("cargo:rustc-link-arg=-Wl,-undefined,dynamic_lookup,-lomp,-L/opt/homebrew/opt/libomp/lib");
} else if cfg!(target_os = "linux") {
println!("cargo:rustc-link-arg=-Wl,-undefined,dynamic_lookup,-lstdc++");
}
} |
When I try to compile the library on Linux I'm getting the error:
For windows I'm getting the following error:
@asg017 would it be possible to fix the scripts to automatically take care of these changes? Edit: I'm dumb and skipped the documentation building on platform for linux the following is required:
It seems however there is no distributable for Windows |
Do you have any issues using the new Rust bindings for
sqlite-vss
? Comment on this issue with any bugs or crashes you come across, or with suggestions on how to make it better.TODOs for Rust bindings:
test.yaml
workflow?The text was updated successfully, but these errors were encountered: